package com.ruoyi.project.system.subjects.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.subjects.domain.Subjects;
import com.ruoyi.project.system.subjects.service.ISubjectsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * subjectsController
 * 
 * @author admin
 * @date 2025-04-24
 */
@Controller
@RequestMapping("/cross/subjects")
public class SubjectsController extends BaseController
{
    private String prefix = "cross/subjects";

    @Autowired
    private ISubjectsService subjectsService;

    @RequiresPermissions("cross:subjects:view")
    @GetMapping()
    public String subjects()
    {
        return prefix + "/subjects";
    }

    /**
     * 查询subjects列表
     */
    @RequiresPermissions("cross:subjects:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Subjects subjects)
    {
        startPage();
        List<Subjects> list = subjectsService.selectSubjectsList(subjects);
        return getDataTable(list);
    }

    /**
     * 导出subjects列表
     */
    @RequiresPermissions("cross:subjects:export")
    @Log(title = "subjects", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Subjects subjects)
    {
        List<Subjects> list = subjectsService.selectSubjectsList(subjects);
        ExcelUtil<Subjects> util = new ExcelUtil<Subjects>(Subjects.class);
        return util.exportExcel(list, "subjects数据");
    }

    /**
     * 新增subjects
     */
    @RequiresPermissions("cross:subjects:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存subjects
     */
    @RequiresPermissions("cross:subjects:add")
    @Log(title = "subjects", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Subjects subjects)
    {
        return toAjax(subjectsService.insertSubjects(subjects));
    }

    /**
     * 修改subjects
     */
    @RequiresPermissions("cross:subjects:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Subjects subjects = subjectsService.selectSubjectsById(id);
        mmap.put("subjects", subjects);
        return prefix + "/edit";
    }

    /**
     * 修改保存subjects
     */
    @RequiresPermissions("cross:subjects:edit")
    @Log(title = "subjects", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Subjects subjects)
    {
        return toAjax(subjectsService.updateSubjects(subjects));
    }

    /**
     * 删除subjects
     */
    @RequiresPermissions("cross:subjects:remove")
    @Log(title = "subjects", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(subjectsService.deleteSubjectsByIds(ids));
    }
}
